<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="Content-Type" content="multipart/form-data;charset=utf-8" />
</head>

<body>
<jsp:include page="../frame.jsp"></jsp:include>
<div id="page-wrapper" >
    <div class="header">
        <h1 class="page-header">
            学生信息管理
        </h1>
        <ol class="breadcrumb">
            <li><a href="/yibinu_certificate/index">首页</a></li>
            <li><a href="/yibinu_certificate/student/list">学生信息管理</a></li>
            <li class="active">
                一键导入Excel数据
            </li>
        </ol>

    </div>

    <div id="page-inner">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-action">
                        选择Excel文件
                    </div>
                    <div class="card-content">
                        <form class="col s12" action="#" method="post" enctype="multipart/form-data">
                            <div class="row">
                                <div class="input-field col s12">
                                    <input id="file" type="file" class="validate" name="file" accept="application/vnd.ms-excel">
                                </div>
                                <div class="input-field col s12">
                                    <button type="button" class="btn" onclick="submitForm()">提交</button>
                                    <script type="text/javascript">
                                        function submitForm() {
                                            var formData = new FormData();
                                            var f = document.getElementById('file');
                                            if (f.files[0] == null){
                                                alert('没有选择文件，请选择一个Excel文件');
                                                return;
                                            }
                                            formData.append('file',f.files[0]);
                                            $.ajax({
                                                async:true,
                                                type:'post',
                                                url:'/yibinu_certificate/student/upload',
                                                data:formData,
                                                contentType: false,
                                                processData: false,
                                                mimeType: "multipart/form-data",
                                                success:function (result) {
                                                    if (result == 'success'){
                                                        alert('操作成功');
                                                    }else {
                                                        alert('操作失败');
                                                    }
                                                    window.location.href = "list";
                                                }
                                            });
                                        }
                                    </script>
                                </div>
                            </div>
                        </form>
                        <div class="clearBoth"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- /. PAGE INNER  -->
</div>
<!-- /. PAGE WRAPPER  -->
</div>
<!-- /. WRAPPER  -->
</body>
</html>